<template>
    <div class="deliverResumeList">
        <h1>已投递简历列表</h1>
        <span v-if="!deliverResumeList" style="color:red">您目前没有投递简历!</span>
        <div v-for="deliverResume in deliverResumeList" :key="deliverResume.deliver_resume_id">
            <el-descriptions title="" direction="vertical" :column="4" border style="margin-bottom:100px">
                <el-descriptions-item label="职位名称">
                    <el-input v-model="deliverResume.job_title" disabled></el-input>
                </el-descriptions-item>
                <el-descriptions-item label="企业名称">
                    <el-input v-model="deliverResume.enterprise_name" disabled></el-input>
                </el-descriptions-item>
                <el-descriptions-item label="企业编号">
                    <el-input v-model="deliverResume.enterprise_number" disabled></el-input>
                </el-descriptions-item>
                <el-descriptions-item label="企业回复">
                    <el-input v-model="deliverResume.enterprise_reply" disabled></el-input>
                </el-descriptions-item>
                <el-descriptions-item label="投递的简历名称">
                    <el-input v-model="deliverResume.resume_name" disabled></el-input>
                </el-descriptions-item>
                <el-descriptions-item label="投递时间">
                    <el-tag size="medium" style="margin-top:5px">{{ format(deliverResume.create_time).format }}</el-tag>
                </el-descriptions-item>
                <el-descriptions-item label="操作">
                    <el-button type="primary" @click="resumeDetail(deliverResume.resume_management_id)">查看该简历</el-button>
                    <el-button type="primary" @click="jobDetail(deliverResume.job_recruitment_id)">查看职位详情</el-button>
                </el-descriptions-item>
            </el-descriptions>
        </div>
        <div style="margin-top:10px;margin-left:-250px;margin-bottom:150px;">
            <div class="block">
                <el-pagination :current-page="currentPage" :page-size="pageSize" layout="total,  prev, pager, next, jumper"
                    :total="total" @current-change="handleCurrentChange">
                </el-pagination>
            </div>
        </div>
    </div>
</template>
<script>
import axios from 'axios';
import dateTime from '@/utils/date_time';
export default {
    data() {
        return {
            deliverResumeList: [],
            pageSize: 2,
            pagerCount: 0,
            total: 0,
            currentPage: 1,
            seeker: {},
        }
    },
    methods: {
        format(create_time) {
            return dateTime.dateTime(create_time)
        },
        resumeDetail(id) {
            this.$router.push({ name: 'resume_detail', params: { resume_management_id: id } }, () => { }, () => { });
        },
        jobDetail(id) {
            this.$router.push({ name: 'job_recruitment_detail', params: { job_recruitment_id: id } }, () => { }, () => { });
        },
        handleCurrentChange(val) {
            if (!window.localStorage.getItem("token")) {
                this.$router.push({ path: '/login' }, () => { }, () => { });
                return;
            }
            let that = this;
            axios({
                method: 'get',
                url: 'http://127.0.0.1:5000/api/deliver_resume/get_list',
                params: {
                    job_seekers: that.seeker.job_seekers,
                    page: val,
                    size: that.pageSize
                },
                headers: {
                    'X-Auth-Token': window.localStorage.getItem("token")
                },
            })
                .then(function (response) {
                    console.log(response.data);
                    that.deliverResumeList = response.data.result.list;
                    that.total = Number.parseInt(response.data.result.count);
                    that.pagerCount = that.total % that.pageSize;
                })
                .catch(function (error) {
                    console.log(error);
                })
                .then(function () {
                    // 总是会执行
                })
        },
    },
    created: function () {
        let that = this;
        axios({
            method: 'get',
            url: 'http://127.0.0.1:5000/api/job_seekers/get_obj',
            params: {
                user_id: window.localStorage.getItem("user_id"),
            },
            headers: {
                'X-Auth-Token': window.localStorage.getItem("token")
            },
        })
            .then(function (response) {
                console.log(response.data)
                if (!response.data.result.obj) {
                    that.$message.error("请先完善您的求职信息");
                    that.$router.push({ naem: 'sseekersInfo' }, () => { }, () => { });
                    return;
                }
                that.seeker = response.data.result.obj;
                let thats = that;
                axios({
                    method: 'get',
                    url: 'http://127.0.0.1:5000/api/deliver_resume/get_list',
                    params: {
                        job_seekers: thats.seeker.job_seekers_id,
                        page: thats.currentPage,
                        size: thats.pageSize
                    },
                    headers: {
                        'X-Auth-Token': window.localStorage.getItem("token")
                    },
                })
                    .then(function (response) {
                        console.log(response.data);
                        that.deliverResumeList = response.data.result.list;
                        that.total = Number.parseInt(response.data.result.count);
                        that.pagerCount = that.total % that.pageSize;
                    })
                    .catch(function (error) {
                        console.log(error);
                    })
                    .then(function () {
                        // 总是会执行
                    })
            })
            .catch(function (error) {
                console.log(error);
            })
            .then(function () {
                // 总是会执行
            })
    }
}
</script>
<style lang="less" scoped>
.deliverResumeList {
    margin-left: 450px;
    margin-top: -500px;
    margin-bottom: 10px;
}
</style>
